package com.qianchang.microfinance.view.mine.renewal;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.dm.library.utils.FormatUtil;
import com.dm.library.utils.StringUtils;
import com.dm.library.widgets.element.DTextView;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.view.base.BaseActivity;
import com.qianchang.microfinance.view.mine.loan.RepayPlanActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/***
 *  续贷申请页面 2018.7.27
 */

public class RenewalApplyActivity extends BaseActivity{

    @BindView(R.id.tv_tobe_settled_id)
    DTextView tvToBeSettled;
    @BindView(R.id.tv_renewal_money_id)
    DTextView tvRenewalMoney;
    @BindView(R.id.tv_deadline)
    DTextView tvTiems;
    @BindView(R.id.tv_serviceFeeRate)
    DTextView tvInterestrate;
    @BindView(R.id.tv_repaymentType)
    DTextView tvRepaymentType;
    @BindView(R.id.tv_loan_usage)
    DTextView tvLoan;
    @BindView(R.id.btn_confirm_rwal_id)
    Button btConfirm;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_renewalapply_layout);
        ButterKnife.bind(this);
        initView();


    }


    @Override
    protected void initView() {
        super.initView();
        setTitleName("续贷申请");

        refreshUi();

    }

    @Override
    protected void initData() {
        super.initData();


    }

    private String tobeSettled = "10002.2";
    private void refreshUi(){

        tvToBeSettled.setTextContent(FormatUtil.numKbPointFormat(tobeSettled));      //借贷金额
        tvRenewalMoney.setTextContent(FormatUtil.numKbPointFormat("10102.2"));      //续贷金额
        tvTiems.setTextContent("12个月");                                             //续贷期限
        tvInterestrate.setTextContent("1.5%/个月");                                   //利率
        tvRepaymentType.setTextContent("先息后本");
        tvLoan.setTextContent("旅游");                                                //消费方式

    }

    @OnClick({R.id.btn_confirm_rwal_id,R.id.oll_reply_plan})
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.oll_reply_plan:                   //还款计划
                checkAndgotoLoanPlan();

                break;
            case R.id.btn_confirm_rwal_id:              //确认续贷


                break;
            default:
                break;
        }
    }


    private double loanAmount;
    private String paybackMode = "3";
    private int paybackPeriod = 12;
    private double monthRate;//就是月利率
    private String serviceFeeSetting = "1";
    private String strRate = "1.50%";
    private double allInterestRate = 180;//总利息

    //跳转到借款计划
    private void checkAndgotoLoanPlan() {

        loanAmount = StringUtils.toDouble(tobeSettled);

        Double d = Double.valueOf(tobeSettled);
        d = (double) Math.round(d * 100) / 100;
        System.out.println(d);

//        loanAmount = StringUtils.toInt(tvToBeSettled.getText().toString().trim(), 0);
        String str = tvToBeSettled.getText().toString().trim();

        Bundle bundle = new Bundle();
        bundle.putDouble("applyAmount", loanAmount); //借款金额
        bundle.putString("repaymentType", paybackMode);// //还款方式  "0"一次性还款付息 , "1"等额本息,"2"等额本金,"3"每月付息，到期还本
        bundle.putString("deadline", String.valueOf(paybackPeriod));    //借款期限
        bundle.putString("reta", monthRate + ""); //利率（月）
        bundle.putString("serviceFeeSetting", serviceFeeSetting); // 是否是固定金额
        if ("0".equals(paybackMode)) {
            bundle.putString("strRate", getString(R.string.Label_daily_interest_rate) + strRate); //天
        } else {
            bundle.putString("strRate", getString(R.string.Label_monthly_interest_rate) + strRate); //月
        }
        bundle.putDouble("allInterestRate", allInterestRate); //总利息
        startActivity(RepayPlanActivity.class, bundle);
    }


}



